[id].vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. <template>
  2. <!-- 页面头部 -->
  3. <HomePageHead></HomePageHead>
  4. <!-- 页面导航 -->
  5. <HomePageNavigation></HomePageNavigation>
  6. <!-- 广告1 -->
  7. <HomeAdvertising :imgurl="adImg1"></HomeAdvertising>
  8. <!-- 面包屑导航 -->
  9. <div class="breadcrumb">
  10. <div class="inner">
  11. <span class="location">当前位置:</span>
  12. <el-breadcrumb :separator-icon="ArrowRight">
  13. <el-breadcrumb-item>
  14. <NuxtLink to="/">首页</NuxtLink>
  15. </el-breadcrumb-item>
  16. <el-breadcrumb-item>
  17. <NuxtLink :to="`/${parent_pinyin}/index.html`">
  18. {{ routLevelTitle }}
  19. </NuxtLink>
  20. </el-breadcrumb-item>
  21. <el-breadcrumb-item>{{ routeNewsTtitle }}</el-breadcrumb-item>
  22. </el-breadcrumb>
  23. </div>
  24. </div>
  25. <!-- 资讯列表 -->
  26. <div class="newsDetail">
  27. <div class="inner">
  28. <div class="innerLeft">
  29. <div class="LeftTop">
  30. <h1>{{ newsDetail.title }}</h1>
  31. <p>
  32. 来源: <span>{{ newsDetail.copyfrom }}</span>
  33. 作者: <span>{{ newsDetail.author }}</span>
  34. 发布时间: <span>{{ time }}</span>
  35. </p>
  36. </div>
  37. <div class="leftBottom" v-html="newsDetail.content" v-if="newsDetail.content" @click="openPreview">
  38. </div>
  39. <div v-if="previewVisible" class="preview-modal" @click="closePreview">
  40. <img :src="selectedImage" alt="Preview">
  41. </div>
  42. <!-- 免责声明: -->
  43. <div class="disclaimer" v-if="newsDetail.fromurl">
  44. <p>原文链接:{{ newsDetail.fromurl }}</p>
  45. <p>[免责声明]本文来源于网络转载,仅供学习交流使用,不构成商业目的。 版权归原作者所有,如涉及作品内容,版权和其他问题,请在30日与本网联系,我们将第一时间处理。</p>
  46. </div>
  47. <div v-if="articleChoice">
  48. <!-- 投票 start ---------------------------------------->
  49. <div class="index_3_box_vote" v-if="articleChoice">
  50. <div class="voteTitle">投票区</div>
  51. <div class="inquire">
  52. <p v-if="voteList.length>0">{{voteList[0].survey_name}}</p>
  53. <div class="radioBox">
  54. <!--投票选项-->
  55. <div v-if="!isDisabled">
  56. <div class="radio" v-if="isRadio">
  57. <el-radio-group v-model="radio1" @change="handleRadioChange">
  58. <el-radio v-for="item in voteList" :key="item.id" :value="item.id" size="large">
  59. <span v-if="item.is_other == 0">{{item.choice_name}}</span>
  60. <span v-else>其他</span>
  61. </el-radio>
  62. </el-radio-group>
  63. <el-input
  64. v-if="showUserChoice"
  65. v-model="userChoice"
  66. :rows="2"
  67. type="textarea"
  68. resize="none"
  69. placeholder="请输入.."
  70. />
  71. </div>
  72. <div class="checkInputBox" v-else>
  73. <el-checkbox-group v-model="check1" @change="handleCheckboxChange">
  74. <span v-for="item in voteList" :key="item.id">
  75. <span v-if="item.is_other == 0">
  76. <el-checkbox size="large" :label="item.choice_name" :value="item.id"/>
  77. </span>
  78. <span v-else>
  79. <el-checkbox size="large" label="其他" :value="item.id"/>
  80. </span>
  81. </span>
  82. </el-checkbox-group>
  83. <el-input
  84. v-if="showUserChoice"
  85. v-model="userChoice"
  86. :rows="2"
  87. type="textarea"
  88. resize="none"
  89. placeholder="请输入.."
  90. />
  91. </div>
  92. </div>
  93. <!--投票结果-->
  94. <div class="inquireData" v-else>
  95. <div v-for="item in websiteSurveyData.data" :key="item.id">
  96. <div class="inquireDataItem active" v-if="item.status == 1">
  97. <div class="inquireDataItemTitle">
  98. <span v-if="item.choice_name == ''">其他</span>
  99. <span v-else>{{item.choice_name}}</span>
  100. </div>
  101. <div class="inquireDataItemNum">{{item.results}}票</div>
  102. </div>
  103. <div class="inquireDataItem" v-else>
  104. <div class="inquireDataItemTitle">
  105. <span v-if="item.choice_name == ''">其他</span>
  106. <span v-else>{{item.choice_name}}</span>
  107. </div>
  108. <div class="inquireDataItemNum">{{item.results}}票</div>
  109. </div>
  110. </div>
  111. </div>
  112. </div>
  113. <div class="btn">
  114. <button class="voting" @click="addWebsiteSurvey" :disabled="isDisabled" v-if="!isDisabled">投票</button>
  115. </div>
  116. </div>
  117. </div>
  118. <!-- 投票 end ---------------------------------------->
  119. </div>
  120. </div>
  121. <div class="innerRight">
  122. <!-- 热点资讯1 -->
  123. <div class="hotList1">
  124. <DetailHotNews></DetailHotNews>
  125. </div>
  126. <!-- 热点资讯2 -->
  127. <div class="hotList2">
  128. <DetailHotNews2></DetailHotNews2>
  129. </div>
  130. </div>
  131. </div>
  132. </div>
  133. <!-- 页面底部 -->
  134. <HomeFoot1></HomeFoot1>
  135. </template>
  136. <script setup>
  137. //1.页面依赖 start ---------------------------------------->
  138. import { onMounted } from 'vue'
  139. import { ElBreadcrumb, ElBreadcrumbItem, ElRadio, ElRadioGroup ,ElMessage,ElCheckboxGroup,ElCheckbox,ElInput} from 'element-plus'
  140. import { ArrowRight } from '@element-plus/icons-vue'
  141. //1.1 获得跳转过来的id
  142. const route = useRoute();
  143. //获得详情id
  144. const articleId = parseInt(route.params.id); //获得该页面的id
  145. //获得当前的完整路径
  146. const fullPath = route.path;
  147. //拆分,取出来中间这一段,然后提取数字部分
  148. const segments = fullPath.split('/');
  149. const targetSegment = segments[1];
  150. // const numberPart = targetSegment.match(/\d+$/)?.[0];
  151. // let routeId = 20 //排除路径错误可以打开这个
  152. // const routeId = numberPart;
  153. let routeId;
  154. //通过导航路径反向查询导航id
  155. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  156. method: 'GET',
  157. query: {
  158. 'pinyin': targetSegment,
  159. },
  160. });
  161. if (getRouteId.code == 200) {
  162. routeId = getRouteId.data.category_id
  163. } else {
  164. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  165. console.log("错误位置:通过url路径查询导航池id")
  166. console.log("后端错误反馈:", getRouteId.message)
  167. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  168. }
  169. //1.2 获得父级栏目的名称、id
  170. const parent_name = ref([]);
  171. const parent_id = ref([]);
  172. const parent_pinyin = ref("");
  173. const parent_children_count = ref(0)
  174. let getParentNav = async () => {
  175. const listData = await requestDataPromise('/web/getOneWebsiteCategory', {
  176. method: 'GET',
  177. query: {
  178. 'catid': routeId
  179. },
  180. });
  181. console.log("获取父级栏目数据")
  182. console.log(listData)
  183. if (listData.code == 200) {
  184. console.log(listData.data);
  185. parent_name.value = listData.data.alias;
  186. parent_id.value = listData.data.parent_id;
  187. parent_pinyin.value = listData.data.aLIas_pinyin;
  188. parent_children_count = listData.data.children_coun;
  189. } else {
  190. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  191. console.log("错误位置:获取面包屑导航")
  192. console.log("后端错误反馈:", listData.message)
  193. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  194. }
  195. }
  196. //获得父级栏目详情
  197. getParentNav();
  198. //1.页面依赖 end ---------------------------------------->
  199. //2.页面数据 start ---------------------------------------->
  200. //2.1 资讯详情
  201. const newsDetail = ref({})
  202. const routeNewsTtitle = ref("");
  203. //2.2 发布日期
  204. const time = ref("");
  205. //2.3 路径
  206. const routLevelTitle = ref("");
  207. const routLevelId = ref("");
  208. //是否展示投票
  209. const articleChoice = ref(false);
  210. //2.4获取详情
  211. async function getPageData() {
  212. const mkdata = await requestDataPromise('/web/selectWebsiteArticleInfo', {
  213. method: 'GET',
  214. query: {
  215. 'articleid': articleId
  216. },
  217. });
  218. if (mkdata.code == 200) {
  219. //判断是否显示投票
  220. if (mkdata.data.is_survey == 1) {
  221. console.log("本篇文章含有投票!")
  222. articleChoice.value = true;
  223. getVoteList();
  224. }
  225. //获取内容
  226. newsDetail.value = mkdata.data;
  227. //获取路径
  228. routLevelTitle.value = newsDetail.value.cat_name;
  229. routLevelId.value = newsDetail.value.category_id;
  230. //获取发布时间
  231. time.value = newsDetail.value.updated_at.split(' ')[0];
  232. //修正标题长度
  233. if (newsDetail.value.title.length >= 20) {
  234. routeNewsTtitle.value = newsDetail.value.title.substr(0, 20) + "...";
  235. } else {
  236. routeNewsTtitle.value = newsDetail.value.title
  237. }
  238. } else {
  239. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  240. console.log("错误位置:获取详情内容")
  241. console.log("后端错误反馈:", mkdata.message)
  242. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  243. }
  244. }
  245. getPageData();
  246. //2.5 获得广告
  247. //广告列表
  248. let adImg1 = ref([]);
  249. onMounted(async () => {
  250. const { $webUrl, $CwebUrl } = useNuxtApp();
  251. //广告1
  252. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=xcw_detail_0001`
  253. const responseAd1 = await fetch(url, {
  254. headers: {
  255. 'Content-Type': 'application/json',
  256. 'Userurl': $CwebUrl,
  257. 'Origin': $CwebUrl
  258. }
  259. });
  260. const resultAd1 = await responseAd1.json();
  261. adImg1.value = resultAd1.data[0];
  262. })
  263. //2.页面数据 end ---------------------------------------->
  264. //3.设置seo信息 start---------------------------------------->
  265. //3.1 设置seo信息
  266. const setData = await requestDataPromise('/web/selectWebsiteArticleInfo', {
  267. method: 'GET',
  268. query: {
  269. 'articleid': articleId
  270. },
  271. });
  272. if (setData.code == 200) {
  273. let seoTitle = setData.data.title;
  274. let seoDescription = setData.data.introduce;
  275. let seoKeywords = setData.data.keyword;
  276. let seoSuffix = setData.data.suffix;
  277. let seoName = setData.data.website_name;
  278. useSeoMeta({
  279. title: seoTitle + "_" + seoName + "_" + seoSuffix,
  280. meta: [
  281. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  282. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 }
  283. ]
  284. });
  285. } else {
  286. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  287. console.log("错误位置:设置详情页面SEO数据")
  288. console.log("后端错误反馈:", setData.message)
  289. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  290. }
  291. //3.设置seo信息 end---------------------------------------->
  292. //4.投票 start---------------------------------------->
  293. const radio1 = ref(''); //单选
  294. const check1 = ref([]); //多选
  295. const isDisabled = ref(false);//是否禁用提交按钮
  296. const isRadio = ref(true);//是否渲染单选
  297. const userSurId = ref('');//投票属于哪一篇文章
  298. const userChoice = ref('');//用于判断用户选择了其他选项以后,输入的值
  299. const userIsChoice = ref('');//用于判断其他选项目前是什么值
  300. const showUserChoice = ref(false);//是否显示其他输入框
  301. const websiteSurveyData = ref([]);//投票结果
  302. //3.2获得投票列表
  303. let voteList = ref([]);
  304. async function getVoteList() {
  305. const voteData = await requestHome('/web/getWebsiteSurvey', { method: 'GET', query: { 'art_id': articleId } });
  306. console.log(778899)
  307. console.log('778899',voteData)
  308. if (voteData.code == 200) {
  309. voteList.value = voteData.data;
  310. console.log(voteList.value)
  311. //判断显示单选还是多选
  312. //survey_type 0是单选 1是多选
  313. if (voteData.data[0].survey_type == 0) {
  314. isRadio.value = true;
  315. console.log("1111")
  316. } else {
  317. isRadio.value = false;
  318. }
  319. //把最后一个的值拿出来 用于判断用户是否选择了其他
  320. for (let item of voteData.data) {
  321. //如果含有其他
  322. if (item.is_other == 1) {
  323. userIsChoice.value = item.id;
  324. }
  325. }
  326. //用户投票属于哪一篇文章
  327. userSurId.value = voteData.data[0].sur_id;
  328. } else {
  329. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  330. console.log("错误位置:首页投票")
  331. console.log("后端错误反馈:", voteData.message)
  332. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  333. }
  334. }
  335. //3.2当用户选择了选项,判断是否展示其他输入框
  336. const handleRadioChange = (value) => {
  337. console.log('11111',value,userIsChoice.value);
  338. if (value == userIsChoice.value) {
  339. showUserChoice.value = true;
  340. } else {
  341. showUserChoice.value = false;
  342. }
  343. }
  344. const handleCheckboxChange = (value) => {
  345. if (value.includes(userIsChoice.value)) {
  346. showUserChoice.value = true;
  347. } else {
  348. showUserChoice.value = false;
  349. }
  350. }
  351. //3.2发起投票
  352. async function addWebsiteSurvey() {
  353. //判断当前是单选还是多选
  354. console.log(isRadio.value)
  355. if (isRadio.value) {
  356. console.log("用户单选!")
  357. if (radio1.value != '') {
  358. //先判断一下是否使用了其他选项
  359. if (showUserChoice.value) {
  360. if (userChoice.value != '') {
  361. //文章id
  362. // console.log(userSurId.value)
  363. // 用户输入的值
  364. // console.log(userChoice.value)
  365. //如果使用了其他,其他的选项需要增加进去
  366. const ChoiceData = await requestHome('/web/addWebsiteSurveyOption', {
  367. method: 'GET',
  368. query: {
  369. 'sur_id': userSurId.value,//投票的新闻id
  370. 'choice_name': userChoice.value,//投票的选项id
  371. }
  372. });
  373. if (ChoiceData.code == 200) {
  374. //提交完其他选项以后,再正式发起投票
  375. const mkData = await requestHome('/web/addWebsiteSurveyVote', {
  376. method: 'GET',
  377. query: {
  378. 'sur_id': userSurId.value,
  379. 'choice_id': ChoiceData.data
  380. }
  381. });
  382. if (mkData.code == 200) {
  383. ElMessage.success('投票成功!')
  384. //把投票结果显示到页面上 禁用投票按钮
  385. isDisabled.value = true;
  386. websiteSurveyData.value = mkData.data;
  387. //遍历一下,把用户选中的那个设置status为1
  388. let data = mkData.data;
  389. //遍历一下,把用户选中的那个设置status为1
  390. for (let item of data.data) {
  391. for (let i of data.choice) {
  392. if (item.id == i) {
  393. console.log(item.id)
  394. item.status = 1;
  395. }
  396. }
  397. }
  398. websiteSurveyData.value = data;
  399. } else {
  400. ElMessage.error(mkData.message)
  401. }
  402. } else {
  403. ElMessage.error('其他投票失败!')
  404. }
  405. } else {
  406. ElMessage.error('请输入选项内容!')
  407. }
  408. } else {
  409. console.log('111',userSurId.value);
  410. console.log('222',radio1.value);
  411. //如果没选择其他,直接提交选择的内容
  412. const mkData = await requestHome('/web/addWebsiteSurveyVote', {
  413. method: 'GET',
  414. query: {
  415. 'sur_id': userSurId.value,
  416. 'choice_id': radio1.value
  417. }
  418. });
  419. if (mkData.code == 200) {
  420. ElMessage.success('投票成功!')
  421. //把投票结果显示到页面上 禁用投票按钮
  422. isDisabled.value = true;
  423. let data = mkData.data;
  424. //遍历一下,把用户选中的那个设置status为1
  425. for (let item of data.data) {
  426. for (let i of data.choice) {
  427. if (item.id == i) {
  428. item.status = 1;
  429. }
  430. }
  431. }
  432. websiteSurveyData.value = data;
  433. } else {
  434. ElMessage.error('投票失败!')
  435. }
  436. }
  437. } else {
  438. ElMessage.error('请选择一个选项')
  439. }
  440. } else {
  441. console.log("多选!")
  442. //多选
  443. if (check1.value != []) {
  444. //先判断一下是否使用了其他选项
  445. if (showUserChoice.value) {
  446. if (userChoice.value != '') {
  447. //判断用户是否只选择了一个其他
  448. if (check1.value.length == 1) {
  449. const ChoiceData = await requestDataPromise('/web/addWebsiteSurveyOption', {
  450. method: 'GET',
  451. query: {
  452. 'sur_id': userSurId.value,//投票的新闻id
  453. 'choice_name': userChoice.value,//用户输入的其他选项文字
  454. }
  455. });
  456. if (ChoiceData.code == 200) {
  457. //提交完其他选项以后,再正式发起投票
  458. const mkData = await requestDataPromise('/web/addWebsiteSurveyVote', {
  459. method: 'GET',
  460. query: {
  461. 'sur_id': userSurId.value,
  462. 'choice_id': ChoiceData.data
  463. }
  464. });
  465. if (mkData.code == 200) {
  466. ElMessage.success('投票成功!')
  467. //把投票结果显示到页面上 禁用投票按钮
  468. isDisabled.value = true;
  469. websiteSurveyData.value = mkData.data;
  470. //遍历一下,把用户选中的那个设置status为1
  471. let data = mkData.data;
  472. //遍历一下,把用户选中的那个设置status为1
  473. for (let item of data.data) {
  474. for (let i of data.choice) {
  475. if (item.id == i) {
  476. console.log(item.id)
  477. item.status = 1;
  478. }
  479. }
  480. }
  481. websiteSurveyData.value = data;
  482. } else {
  483. ElMessage.error(mkData.message)
  484. }
  485. } else {
  486. ElMessage.error('其他投票失败!')
  487. }
  488. } else {
  489. //用户选择了除了其他以外,还包括别的选项
  490. const ChoiceData = await requestDataPromise('/web/addWebsiteSurveyOption', {
  491. method: 'GET',
  492. query: {
  493. 'sur_id': userSurId.value,//投票的新闻id
  494. 'choice_name': userChoice.value,//用户输入的其他选项文字
  495. }
  496. });
  497. if (ChoiceData.code == 200) {
  498. let data = check1.value;
  499. //找到多选的数组,把其他默认值给替换掉
  500. for (let i = 0; i < data.length; i++) {
  501. if (data[i] == userIsChoice.value) {
  502. data[i] = ChoiceData.data;
  503. }
  504. }
  505. let jsonArray = JSON.stringify(data);
  506. //提交完其他选项以后,再正式发起投票
  507. const mkData = await requestDataPromise('/web/addWebsiteSurveyVote', {
  508. method: 'GET',
  509. query: {
  510. 'sur_id': userSurId.value,
  511. 'choice_id': jsonArray
  512. }
  513. });
  514. if (mkData.code == 200) {
  515. ElMessage.success('投票成功!')
  516. //把投票结果显示到页面上 禁用投票按钮
  517. isDisabled.value = true;
  518. websiteSurveyData.value = mkData.data;
  519. //遍历一下,把用户选中的那个设置status为1
  520. let data = mkData.data;
  521. //遍历一下,把用户选中的那个设置status为1
  522. for (let item of data.data) {
  523. for (let i of data.choice) {
  524. if (item.id == i) {
  525. //console.log(item.id)
  526. item.status = 1;
  527. }
  528. }
  529. }
  530. websiteSurveyData.value = data;
  531. } else {
  532. ElMessage.error(mkData.message)
  533. }
  534. } else {
  535. ElMessage.error('其他投票失败!')
  536. }
  537. }
  538. } else {
  539. ElMessage.error('请输入选项内容!')
  540. }
  541. } else {
  542. let jsonArray = JSON.stringify(check1.value);
  543. //如果没选择其他,直接提交选择的内容
  544. const mkData = await requestDataPromise('/web/addWebsiteSurveyVote', {
  545. method: 'GET',
  546. query: {
  547. 'sur_id': userSurId.value,
  548. 'choice_id': jsonArray
  549. }
  550. });
  551. if (mkData.code == 200) {
  552. ElMessage.success('投票成功!')
  553. //把投票结果显示到页面上 禁用投票按钮
  554. isDisabled.value = true;
  555. websiteSurveyData.value = mkData.data;
  556. //遍历一下,把用户选中的那个设置status为1
  557. let data = mkData.data;
  558. //遍历一下,把用户选中的那个设置status为1
  559. for (let item of data.data) {
  560. for (let i of data.choice) {
  561. if (item.id == i) {
  562. console.log(item.id)
  563. item.status = 1;
  564. }
  565. }
  566. }
  567. websiteSurveyData.value = data;
  568. } else {
  569. ElMessage.error('投票失败!')
  570. }
  571. }
  572. } else {
  573. ElMessage.error('请选择一个选项')
  574. }
  575. }
  576. }
  577. //4.投票 end---------------------------------------->
  578. //5.页面图片放大 start---------------------------------------->
  579. const previewVisible = ref(false)
  580. const selectedImage = ref(' ')
  581. const openPreview = (event) => {
  582. if (event.target.tagName === 'IMG') {
  583. selectedImage.value = event.target.src;
  584. previewVisible.value = true;
  585. }
  586. }
  587. const closePreview = () => {
  588. previewVisible.value = false;
  589. }
  590. //5.页面图片放大 end---------------------------------------->
  591. </script>
  592. <style lang="less" scoped>
  593. @import url('@/assets/css/detail.less');
  594. </style>